<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>

  <div id="box" class="cba" title="aaa" style="color: red;">
    哈哈哈
  </div>

    <button class="btn">切换</button>


    <div class="box">
      <span>呵呵呵</span>
      <p>哈哈哈</p>
    </div>

  <script>

    console.log(window.outerHeight);
    console.log(document.documentElement.offsetWidth);
    
    var box = document.querySelector("#box")
    var btnEl = document.querySelector(".btn")

    btnEl.id = "aaa"
    console.log(btnEl.getAttribute("id"));

    btnEl.onclick = function() {
      if (box.hidden == false) {
        box.hidden = true
        box.style.display = "none"
      } else {
        box.hidden = false
        box.style.display = "block"
      }
    }

    var boxClass = document.querySelector(".box")
    var h2El = document.createElement("h2")
    h2El.className = "title"
    h2El.classList.add("active")
    h2El.textContent = "我是标题"
    boxClass.firstElementChild.after(h2El)
  </script>
</body>
</html>